import re

j = {}


def init_json():
    j["新人物基址"] = "NewPersonBase"
    j["人物基址"] = "PersonBase"
    j["人物CALL"] = "PersonCall"
    j["角色等级"] = "Level"
    j["制裁基址"] = "CraftBase"
    j["评分基址"] = "ScoreBase"
    j["账号基址"] = "AccountBase"
    j["喇叭公告"] = "NoticeBase"
    j["公告参数"] = "NoticeParam"
    j["公告参数1"] = "NoticeParam1"
    j["公告CALL"] = "NoticeCall"
    j["神话CALL"] = "MythicCall"
    j["角色基址"] = "RoleBase"
    j["城镇坐标"] = "TownBase"
    j["觉醒次数"] = "AwakeningTimes"
    j["转职判断"] = "TransferJudge"
    j["角色类型"] = "RoleType"
    j["基本职业"] = "BasicJob"
    j["背包基址"] = "BagBase"
    j["商店基址"] = "ShopBase"
    j["副职业_RCX"] = "SubJob_RCX"
    j["冷却参数_1"] = "CoolingParam_1"
    j["冷却参数_2"] = "CoolingParam_2"
    j["游戏状态"] = "GameState"
    j["房间编号"] = "RoomNumber"
    j["最大疲劳"] = "MaxFatigue"
    j["当前疲劳"] = "CurrentFatigue"
    j["自动捡物"] = "AutoPickUp"
    j["拾取范围_上"] = "PickUpRange_Up"
    j["拾取范围_下"] = "PickUpRange_Down"
    j["拾取范围_左"] = "PickUpRange_Left"
    j["拾取范围_右"] = "PickUpRange_Right"
    j["瞬移HOOK"] = "InstantMove"
    j["瞬移CALL"] = "InstantMoveCall"
    j["修理契约"] = "RepairContract"
    j["城镇大区域"] = "TownArea"
    j["城镇小区域"] = "TownSubArea"
    j["地图边距"] = "MapMargin"
    j["鼠标基址"] = "MouseBase"
    j["角色指针"] = "RolePointer"
    j["界面基址"] = "InterfaceBase"
    j["界面指针"] = "InterfacePointer"
    j["选图基址"] = "SelectBase"
    j["开始翻牌"] = "StartFlip"
    j["ESC状态"] = "ESCState"
    j["HOOK变怪"] = "HookMonster"
    j["城镇坐标X"] = "TownBaseX"
    j["城镇坐标Y"] = "TownBaseY"
    j["范围右侧"] = "RangeRight"
    j["范围左侧"] = "RangeLeft"
    j["范围下侧"] = "RangeBottom"
    j["范围上侧"] = "RangeTop"
    j["范围脚部"] = "RangeFoot"
    j["范围头部"] = "RangeHead"
    j["独家全屏"] = "ExclusiveFullScreen"
    j["全局钩子"] = "GlobalHook"
    j["学习技能CALL"] = "LearnSkillCall"
    j["界面CALL"] = "InterfaceCall"
    j["界面RCX"] = "InterfaceRCX"
    j["副本编号"] = "CopyNumber"
    j["副本名称"] = "CopyName"
    j["方框公告"] = "BoxNotice"
    j["城镇瞬移RDX"] = "TownInstantMoveRDX"
    j["选图CALL"] = "SelectCopyCall"
    j["进图CALL"] = "EnterCopyCall"
    j["收包地址"] = "ReceivePackageAddress"
    j["收包HOOK_1"] = "ReceivePackageHook_1"
    j["收包HOOK_2"] = "ReceivePackageHook_2"
    j["收包CALL"] = "ReceivePackageCall"
    j["独家收包_1"] = "ExclusiveReceivePackage_1"
    j["收包跳回"] = "ExclusiveReceivePackage_2"
    j["独家收包_2"] = "ExclusiveReceivePackage_3"
    j["收包跳转"] = "ExclusiveReceivePackage_4"
    j["汇编CALL"] = "AssemblyCall"
    j["内存汇编"] = "AssemblyAddress"
    j["ThreadAssemblyCall"] = "ThreadAssemblyCall"
    j["时间基址"] = "TimeBase"
    j["冷却判断_1"] = "CoolingJudge_1"
    j["冷却判断_2"] = "CoolingJudge_2"
    j["宽高偏移"] = "WidthHeightOffset"
    j["选中地图ID"] = "SelectedMapID"
    j["选中地图难度"] = "SelectedMapDifficulty"
    j["顺图偏移"] = "MapOverOffset"
    j["方向ID"] = "DirectionID"
    j["地图偏移"] = "MapOffset"
    j["坐标顺图"] = "MapCoordinateOffset"
    j["门型偏移"] = "DoorOffset"
    j["索引偏移"] = "IndexOffset"
    j["数组偏移"] = "ArrayOffset"
    j["当前房间_X"] = "CurrentRoom_X"
    j["当前房间_Y"] = "CurrentRoom_Y"
    j["BOSS房间_X"] = "BOSSRoom_X"
    j["BOSS房间_Y"] = "BOSSRoom_Y"
    j["是否开门"] = "IsOpen"
    j["动作ID"] = "ActionID"
    j["篝火偏移"] = "CampfireOffset"
    j["技能栏"] = "SkillBar"
    j["技能栏偏移"] = "SkillBarOffset"
    j["技能等级"] = "SkillLevel"
    j["地图开始"] = "MapStart"
    j["地图结束"] = "MapEnd"
    j["装备栏索引偏移1"] = "EquipmentBarIndexOffset1"
    j["装备栏索引偏移2"] = "EquipmentBarIndexOffset2"
    j["比拉谢尔索引偏移"] = "BraxisIndexOffset"
    j["比拉谢尔分页偏移"] = "BraxisPageOffset"
    j["副职业偏移"] = "SubJobOffset"
    j["分解机等级"] = "DecomposeLevel"
    j["分解机耐久"] = "DecomposeDurability"
    j["碰撞状态"] = "CollisionState"
    j["界面指针偏移"] = "InterfacePointerOffset"
    j["背包ID"] = "BagID"
    j["游戏菜单ID"] = "GameMenuID"
    j["高价值定制属性装备ID"] = "HighValueCustomAttribute"
    j["回城弹窗确认ID"] = "BackHomeConfirmID"
    j["畅游指针偏移"] = "BackHomePointerOffset"
    j["畅游完成任务偏移"] = "BackHomeTaskOffset"
    j["阵营偏移"] = "CampOffset"
    j["怪物血量"] = "MonsterHP"
    j["类型偏移"] = "TypeOffset"
    j["地面物品"] = "GroundItem"
    j["物品名称"] = "ItemName"
    j["读取坐标"] = "ReadCoordinateOffset"
    j["对象坐标"] = "ObjectCoordinate"
    j["ESC状态标记"] = "ESCStateMark"
    j["翻牌基址"] = "FlipBase"
    j["传送阵ID"] = "TeleportationID"
    j["传送阵偏移"] = "TeleportationOffset"
    j["传送左右基址"] = "TeleportationLeftRight"
    j["通关商店ID"] = "PassShopID"
    j["人物名望"] = "PersonFame"
    # j["选中地图编号"] = "SelectedMapNumber"
    j["角色初始指针"] = "RoleInitialPointer"
    j["普通角色数量"] = "NormalRoleNumber"
    j["普通角色位置"] = "NormalRolePosition"
    j["满血偏移"] = "FullHP"
    j["背包指针"] = "BagPointer"
    j["装备品级"] = "EquipmentLevel"
    j["物品代码"] = "ItemCode"
    j["强化偏移"] = "EnhanceOffset"
    j["装备部位"] = "EquipmentPart"
    j["装备红字"] = "EquipmentRed"
    j["装备选中"] = "EquipmentSelected"
    j["装备处理确认ID"] = "EquipmentProcessConfirmID"
    j["畅玩经验"] = "ChallengeExperience"
    j["组件偏移"] = "ComponentOffset"
    j["组件偏移开始"] = "ComponentOffsetStart"
    j["组件偏移结束"] = "ComponentOffsetEnd"
    j["学习技能偏移"] = "LearnSkillOffset"
    j["建筑穿透"] = "BuildingPenetration"
    j["地图穿透"] = "MapPenetration"
    j["区域参数"] = "AreaParam"
    j["区域偏移"] = "AreaOffset"
    j["武器偏移"] = "WeaponOffset"
    j["称号偏移"] = "TitleOffset"
    j["上衣偏移"] = "ChestOffset"
    j["头肩偏移"] = "ShoulderOffset"
    j["下装偏移"] = "PantsOffset"
    j["鞋子偏移"] = "ShoesOffset"
    j["腰带偏移"] = "BeltOffset"
    j["项链偏移"] = "NecklaceOffset"
    j["手镯偏移"] = "BraceletOffset"
    j["戒指偏移"] = "RingOffset"
    j["辅助装备"] = "AssistEquipment"
    j["魔法石偏移"] = "MagicStoneOffset"
    j["副武器偏移"] = "SecondaryWeaponOffset"
    j["耳环偏移"] = "EarringOffset"
    j["冰冻开始"] = "IceFrozenStart"
    j["冰冻结束"] = "IceFrozenEnd"
    j["攻击速度"] = "AttackSpeed"
    j["移动速度"] = "MoveSpeed"
    j["释放速度"] = "ReleaseSpeed"
    j["当前耐久"] = "CurrentDurability"
    j["名称偏移"] = "NameOffset"
    j["最低技能学习等级"] = "MinimumSkillLearningLevel"
    j["畅玩窗口ID"] = "ChallengeWindowID"
    j["控制板ID"] = "ControlBoardID"
    j["全局空白"] = "GlobalBlank"
    j["全局空白2"] = "GlobalBlank2"
    j["装备栏偏移"] = "EquipmentBarOffset"
    j["消耗栏偏移"] = "ConsumeBarOffset"
    j["评分偏移"] = "ScoreOffset"
    j["强森无敌偏移"] = "QSInvincibleOffset"
    j["无敌偏移"] = "InvincibleOffset"
    j["地图边距_X"] = "MapMargin_X"
    j["地图边距_Y"] = "MapMargin_Y"
    j["代码偏移"] = "CodeOffset"
    j["数量偏移"] = "NumberOffset"
    j["角色大区"] = "RoleArea"
    j["副职业ID"] = "SubJobID"
    j["分解机面板ID"] = "DecomposeMachinePanelID"
    j["角色端口标识"] = "RolePortalMark"
    j["选图CALL"] = "SelectMapCall"
    j["进图CALL"] = "EnterMapCall"
    j["无限聚物"] = "InfiniteCluster"
    j["过图CALL"] = "PassMapCall"
    j["区域Call_R9"] = "AreaCall_R9"
    j["区域R9"] = "AreaR9"
    j["区域CALL"] = "AreaCall"
    j["调用BUFFCALL"] = "CallBUFF"
    j["特效基址"] = "EffectBase"
    j["BUFF参数1"] = "BUFFParam1"
    j["BUFF参数2"] = "BUFFParam2"
    j["特效缓冲CALL"] = "EffectBufferCall"
    j["特效关闭CALL"] = "EffectCloseCall"
    j["特效释放CALL"] = "EffectReleaseCall"
    j["发包基址"] = "SendPacketBase"
    j["缓冲CALL"] = "SendPacketBufferCall"
    j["赋值CALL"] = "SendPacketAssignCall"
    j["发包CALL"] = "SendPacketCall"
    j["加密CALL"] = "EncryptCall"
    j["加密CALL2"] = "EncryptCall2"
    j["加密CALL4"] = "EncryptCall4"
    j["加密CALL8"] = "EncryptCall8"
    j["独家汇编"] = "ExclusiveAssembly"


def regex_replace(pattern, repl, string):
    return re.sub(pattern, repl, string)


def print_addr():
    all = ""
    with open("addr.txt", "r") as file:
        lines = file.readlines()
        kb = ""
        for line in lines:
            if line == '\n':
                continue
            if line.find("0x00000000") != -1:
                kb += line
            index = line.index("=")
            if index != -1:
                a = line[0:index]
                b = j.get(a)
                if b is None:
                    continue
                ##if b is not None:
                ## line = regex_replace(r'\r\n', line, '')
                line = line.replace(a, b)
                line = line.replace(";", ";//" + a)
                ## line = regex_replace(r'\r\n', line, '')
                all += "const auto " + line

    print(all)
    print("\r\n")
    print(kb)


def print_struct():
    all = "enum EnumAddr{\r\n"
    with open("addr.txt", "r") as file:
        lines = file.readlines()
        for line in lines:
            index = line.index("=")
            if index != -1:
                a = line[0:index]
                b = j.get(a)
                if b is None:
                    continue
                all += "\t" + b + ",//" + a + "\r\n"
    all += "}"
    print(all)


def print_addr2():
    all = ""
    with open("addr.txt", "r") as file:
        lines = file.readlines()
        for line in lines:
            if line is None or line.find("=") == -1 or line.find(";") == -1:
                continue
            eq = line.index("=")
            end = line.index(";")
            if eq == -1 or end == -1:
                continue
            a = line[0:eq]
            b = j.get(a)
            if b is None:
                continue
            ##if b is not None:
            ## line = regex_replace(r'\r\n', line, '')

            val = line[eq + 1:end]
            val = val.replace("0x", "")
            ##t = "\t\"" + b + "\":"
            t = val + "#"
            ##line = line.replace(a, b)
            ## line = line.replace(";", ";//" + a)
            ## line = regex_replace(r'\r\n', line, '')
            ##t.replace(",", "")
            all += t

    print(all)


if __name__ == '__main__':
    init_json()
    ## print_addr2()
    ## print_struct()
    print_addr()
